package com.smallsoft.adapter;

import java.util.ArrayList;

import com.smallsoft.beans.Content;
import com.smallsoft.util.ImageViewRounded;
import com.smallsoft14.phongtucvietnam.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ContentAdapter extends BaseAdapter{

	ArrayList<Content> contents = new ArrayList<Content>();
	Context context;
	LayoutInflater layoutInflater;
	int position;
	private int[] images = new int[] {
			R.drawable.cuoihoi,
			R.drawable.sinhduong,
			R.drawable.giaothiep,
			R.drawable.daohieu,
			R.drawable.tangle,
			R.drawable.tet,
			R.drawable.chonngaygio,
	};
	
	public ContentAdapter(Context context, ArrayList<Content> contents, int position){
		this.contents = contents;
		this.context = context;
		this.position = position;
		layoutInflater = LayoutInflater.from(context);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return contents.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return contents.get(position);
	}

	@Override
	public long getItemId(int id) {
		// TODO Auto-generated method stub
		return id;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Content content = contents.get(position);
		layoutInflater = (LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
		if(convertView == null){
			convertView = layoutInflater.inflate(R.layout.list_content_item, parent, false);
		}
		TextView title = (TextView)convertView.findViewById(R.id.title);
		title.setText(content.getTitle());
		ImageViewRounded icon = (ImageViewRounded)convertView.findViewById(R.id.icon_cat);
		icon.setImageResource(images[ContentAdapter.this.position]);
		return convertView;
	}

}
